<?php require VIEWPATH . ADMIN_DIR . DIRECTORY_SEPARATOR . 'header.php' ?>
<style type="text/css">
.dropdown-grade {
	margin-left: 10px;
}
.dropdown-grade li a{
	line-height: 24px;
}
#input-student {
	background-color: #FFF !important;
}
.div-submit {
	margin-top: 20px;
}
</style>
<div class="page-header">
	<h1>
		<a class="a-back" href="<?= admin_url('contents/exam_room_data/' . $examId) ?>">
            <i class="fa fa-reply"></i>
		</a>
		<?php if(isset($roomId)): ?>
			修改考试 编号<?= $roomId ?>
		<?php else: ?>
			添加考试
		<?php endif ?>

	</h1>
</div>
<div class="col-xs-12">
	<form id="exam-room-form" class="form-horizontal">
		<!-- 考试id -->
		<input type="hidden" name="exam_id" value="<?= $examId ?>" />
        <input type="hidden" name="room_id" value="<?= isset($roomId) ? $roomId : '' ?>" />
        <!-- 巡考老师提交输入框 -->
		<input type="hidden" name="outside_teacher_ids" value='<?= isset($room['outside_teachers']) ? $room['outside_teachers'] : '' ?>' />
		<!-- 放学学生提交输入框 -->
		<input type="hidden" name="free_student_ids" value='<?= isset($room['free_students']) ? $room['free_students'] : '' ?>' />
        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right">场次：</label>
            <div class="col-sm-6">
                <input class="form-control" type="number" name="timeslot" value="<?= isset($room['timeslot']) ? $room['timeslot'] : 1 ?>" placeholder="请填写场次，只能填数字" />
            </div>
        </div>
		<div class="form-group">
            <label class="col-sm-3 control-label no-padding-right">年级：</label>
            <div class="col-sm-6">
				<select class="form-control" name="grade">
					<?php foreach($grades as $grade): ?>
                        <option value="<?= $grade['id'] ?>" <?php if(isset($room['grade_id']) && $grade['id'] == $room['grade_id']): ?>selected<?php endif ?>>
                            <?= $grade['grade_name'] ?>
                        </option>
					<?php endforeach ?> 
				</select>
            </div>
		</div>
		<div class="form-group">
            <label class="col-sm-3 control-label no-padding-right">科目：</label>
            <div class="col-sm-6">
				<select class="form-control" name="subject">
					<?php foreach($subjects as $subject): ?>
                        <option value="<?= $subject['id'] ?>"<?php if(isset($room['lesson_id']) && $subject['id'] == $room['lesson_id']): ?>selected<?php endif ?>>
                            <?= $subject['lesson_name'] ?>
                        </option>
					<?php endforeach ?> 
				</select>
            </div>
		</div>
		<div class="form-group">
            <label class="col-sm-3 control-label no-padding-right">巡考教师：</label>
			<span class="block input-icon input-icon-right pd0">
				<div class="col-sm-6">
					<span class="block input-icon input-icon-right pd0">
						<input class="width-100" type="text" placeholder="请选择教师" id="select-teacher" value="<?= isset($room['teacherNames']) ? $room['teacherNames'] : '' ?>" />
						<i class="ace-icon fa fa-user"></i>
					</span>
				</div>
            </span>
		</div>
		<div class="form-group">
            <label class="col-sm-3 control-label no-padding-right">放学学生：</label>
            <div class="col-sm-6">
				<span class="block input-icon input-icon-right pd0" data-toggle="dropdown">
					<input class="width-100" id="input-student" type="text" placeholder="请选择学生" name="student-name" readonly value="<?= isset($room['studentNames']) ? $room['studentNames'] : '' ?>" />
					<i class="ace-icon fa fa-user"></i>
				</span>
				<ul class="dropdown-menu dropdown-grade">
					<?php foreach($grades as $grade): ?>
						<li>
							<a id="select-student-<?= $grade['id'] ?>"><?= $grade['grade_name'] ?></a>
						</li>
					<?php endforeach ?>
				</ul>
			</div>
		</div>
		<div class="form-group">
            <label class="col-sm-3 control-label no-padding-right">日期：</label>
            <div class="col-sm-6">
				<input class="width-100 date-input" type="text" name="day" value="<?= isset($room['day']) ? $room['day'] : date('Y-m-d') ?>" />
            </div>
		</div>
		<div class="form-group">
            <label class="col-sm-3 control-label no-padding-right">时间：</label>
            <div class="col-sm-6">
				<input class="width-10 hour-input" type="text" name="start" value="<?= isset($room['begin']) ? $room['begin'] : '09:00' ?>" />
				&nbsp;&nbsp; — &nbsp;&nbsp;
				<input class="width-10 hour-input" type="text" name="end" value="<?= isset($room['end']) ? $room['end'] : '11:00' ?>" />
            </div>
		</div>
		<div class="form-group">
            <label class="col-sm-3 control-label no-padding-right">类型：</label>
            <div class="col-sm-6">
				<select class="form-control" name="type">
					<?php foreach($types as $value => $name): ?>
                        <option value="<?= $value ?>" <?php if(isset($room['type']) && $value === $room['type']): ?>selected<?php endif ?>>
                            <?= $name ?>
                        </option>
					<?php endforeach ?> 
				</select>
            </div>
		</div>
        <div class="clearfix div-submit">
            <div class="col-md-offset-3 col-md-9">
                <button class="btn btn-info" type="submit">
                    <i class="ace-icon fa fa-check"></i> 提交
                </button>
            </div>
        </div>
	</form>
</div>

<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'footer.php'?>
<script type="text/javascript">
	var table = "";
	$(function(){
		// 初始化选择老师控件
		$("#select-teacher").selectTeacher({
			"multiSelect": true,
			"resultDom": $("[name=outside_teacher_ids]"),
		});
		// 初始化选择学生控件
		<?php foreach($grades as $grade): ?>
			$("#select-student-<?= $grade['id'] ?>").selectStudent({
				"modalDataUrl": '<?= admin_url('contents/select_student_plugin_data_source') . '?grade_id=' . $grade['id'] ?>',
				"multiSelect": true,
				"resultDom": $("[name=free_student_ids]")
			});
		<?php endforeach ?>
		// 日期选择器
		var dateformat = 'YYYY-MM-DD';
		var hourformat = 'HH:mm';
		$(".date-input").datetimepicker({
			format: dateformat
		})
		$(".hour-input").datetimepicker({
			format: hourformat
		})
		// 提交表单
		var form = $("#exam-room-form");
		var submitUrl = "<?=admin_url('contents/save_exam_room_action')?>";
		form_submit(form, submitUrl, function(res) {
			tips_alert(res.msg, res.success, function(){
				if(res.success) {
					window.location.href = "<?=admin_url('contents/exam_room_data/' . $examId)?>";
				}
			});
		})
	})
</script>